<?php

/**
 * Inventory Form
 *
 * @category   Cms
 * @package    Cms_Form
 */

class Cms_Form_Inventory_Inventory_Form extends BIS_Form_Abstract
{
    public function init()
    {
        // add path to custom validators & filters
        $this->addElementPrefixPath('Cms_Decorator',
                            	     APPLICATION_PATH . '/modules/cms/models/decorator/',
                            	    'decorator');
       
        $this->setMethod('post');

        $catalogModel = new Cms_Model_Catalog();
        $catalogModelProducts = $catalogModel->getProductsByCategory(0);
        $catalogModelSuppliers = $catalogModel->getSuppliers();

        $products = array();
        $products[NULL] = ' --- Select Product Name --- ';
        foreach($catalogModelProducts as $product) {
            $products[$product->productId] = $product->name;
        }
        
        $suppliers = array();
        $suppliers[NULL] = ' --- Select Supplier Name --- ';
        foreach($catalogModelSuppliers as $supplier) {
            $suppliers[$supplier->supplierId] = $supplier->name;
        }
    
        $this->addElement('select', 'productId', array(
            'label' => 'Product Name',
            'required' => true,
            'multiOptions' => $products
        ));

        $this->addElement('select', 'supplierId', array(
            'label' => 'Supplier Name',
            'required' => true,
            'multiOptions' => $suppliers
        ));

        $this->addElement('text', 'quantity',array(
            'label' => 'Quantity',
            'size' => 5,
            'required' => true,
            'validators' => array('Int')
        ));

        $this->addElement('text', 'price', array(
        		'label' => 'Price',
        		'size' => 5,
        		'required' => true,
        		'validators' => array('Float')
        ));
        
        $this->addElement('text', 'orderDate',array(
            'label' => 'Order Date',
            'size' => 20,
            'required' => true,
            'validators' => array(array('Date', true, array('dd/MM/yyyy'))),
            'filters' => array('StringTrim')
        ));

        $this->setElementDecorators(array(
            'ViewHelper',
            'FormElementsErrors',
             array(array('data' => 'HtmlTag'),  array('tag' =>'td')),
              'FormElementsLabel',
            array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
        ));

        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table', 'class'=> 'form')),
            'Form'
        ));
    }
}